package com.jsh.erp.controller;

import com.jsh.erp.service.sequence.SequenceService;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.ErpInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value = "/sequence")
@Api(tags = {"单据编号"})
public class SequenceController {
    private Logger logger = LoggerFactory.getLogger(SequenceController.class);

    @Resource
    private SequenceService sequenceService;

    /**
     * 零售管理——零售出库——新增
     *          零售退货——新增
     * 采购管理——请购单——新增，复制
     *          采购订单——新增，复制
     *          采购入库——新增，复制
     *          采购退货——新增，复制
     * 销售管理——销售订单——新增，复制
     *          销售出库——新增，复制
     *          销售退货——新增，复制
     * 财务管理——收款单——新增
     *         付款单——新增
     *         收预付款单——新增
     */
    @GetMapping(value = "/buildNumber")
    @ApiOperation(value = "自动生成单据编号")
    public BaseResponseInfo buildNumber(HttpServletRequest request)throws Exception {
        BaseResponseInfo res = new BaseResponseInfo();
        Map<String, Object> map = new HashMap<String, Object>();
        try {
            String number = sequenceService.buildOnlyNumber();
            map.put("defaultNumber", number);
            res.code = ErpInfo.OK.code;
            res.data = map;
        } catch(Exception e){
            logger.error(e.getMessage(), e);
            res.code = ErpInfo.ERROR.code;
            res.data = ErpInfo.ERROR.name;;
        }
        return res;
    }

}
